<?php

declare(strict_types=1);

namespace Modules\Production\Models;

use Modules\Base\Models\Material;
use Catch\Base\CatchModel as Model;

/**
 * @property $id
 * @property $order_id
 * @property $material_no
 * @property $qty
 * @property $wms_code
 * @property $unit
 * @property $row_num
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class PickOrderDetail extends Model
{


    protected $table = 'pick_order_detail';

    protected $fillable = [ 'id','production_no','split_qty','supplier_code','fid','fentryid','location', 'order_id', 'material_no', 'qty', 'wms_code', 'unit', 'row_num','lot_num', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];

    /**
     * @var array
     */
    protected array $fields = ['id','production_no','split_qty','supplier_code','fid','fentryid','location','order_id','material_no','qty','wms_code','unit','row_num','lot_num','created_at','updated_at'];

    /**
     * @var array
     */
    protected array $form = ['id','production_no','split_qty','supplier_code','fid','fentryid','location','order_id','material_no','qty','wms_code','unit','row_num','lot_num','created_at','updated_at'];

    /**
     * @var array
     */
    public array $searchable = [
        'order_id'      => '=',
        'production_no' => '=',
    ];

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

    /**
     * 关联领料单
     */
    public function order(){
        return $this->belongsTo(PickOrder::class,'order_id');
    }

    /**
     * 关联产品信息
     * @return mixed
     */
    public function material(){
        return $this->hasOne(Material::class,'fnumber','material_no');
    }

}
